﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TMIS.DAL
{
    public class Profession
    {
        private Model.ThesisDB db = new Model.ThesisDB();

        #region 对专业表查询数据功能的实现
        /// <summary>
        /// 获取专业表中所有专业名称
        /// </summary>
        /// <returns></returns>
        public string[] Search()
        {
            string[] profession = (from p in db.Profession
                                   select p.Name).ToArray();
            return profession;
        }
        /// <summary>
        /// 获取专业表中指定院系名称对应的所有专业
        /// </summary>
        /// <param name="guid">院系名称对应的ID号</param>
        /// <returns></returns>
        public string[] Search(Guid guid)
        {
            string[] profession = (from p in db.Profession
                                   where p.DepartmentID == guid
                                   select p.Name).ToArray();
            return profession;
        }
        /// <summary>
        /// 获取指定专业名称对应的ID号
        /// </summary>
        /// <param name="profession">专业名称</param>
        /// <returns></returns>
        public Guid Search(string profession)
        {
            Guid guid = (from p in db.Profession
                         where p.Name == profession
                         select p.ID).FirstOrDefault();
            return guid;
        }
        #endregion

        #region 对专业表插入数据功能的实现
        /// <summary>
        /// 将专业信息数据写入到专业表中
        /// </summary>
        /// <param name="profession"></param>
        public void Insert(Model.Profession profession)
        {
            db.Profession.InsertOnSubmit(profession);
            db.SubmitChanges();
        }
        #endregion

        #region 对专业表删除数据功能的实现
        /// <summary>
        ///删除指定的专业信息数据
        /// </summary>
        /// <param name="profession"></param>
        public void Delete(string profession)
        {
            Model.Profession pro = db.Profession.Single(e => e.Name == profession);
            db.Profession.DeleteOnSubmit(pro);
            db.SubmitChanges();
        }
        #endregion
    }
}
